using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SafeAreaFitter : MonoBehaviour
{
    private RectTransform rectTransform;

    void Awake()
    {
        rectTransform = GetComponent<RectTransform>();
        Debug.Log($"hxtest area: {Screen.safeArea}");
        ApplySafeArea();
    }

    private void ApplySafeArea()
    {
        Vector2 anchorMin = Vector2.zero;
        Vector2 anchorMax = Vector2.zero + new Vector2(Screen.width, Screen.safeArea.height);

        anchorMin.x /= Screen.width;
        anchorMin.y /= Screen.height;
        anchorMax.x /= Screen.width;
        anchorMax.y /= Screen.height;

        rectTransform.anchorMin = anchorMin;
        rectTransform.anchorMax = anchorMax;

        rectTransform.offsetMin = Vector2.zero;
        rectTransform.offsetMax = Vector2.zero;
    }
}
